home *** CD-ROM | disk | FTP | other *** search
- #if defined( Uses_Strings ) && !defined( __Strings )
- #define __Strings
-
- /********************************************************************/
- /* File: Strings.h */
- /* Author: Patrick Reilly */
- /* CIS ID: 70274,161 */
- /* Description: */
- /* Strings.h is the header file for using the class Strings. */
- /* Strings is an easy-to-use class that abstracts string usage in */
- /* a TV application. This makes program modification (especially */
- /* in the area of internationalization) easy. */
- /********************************************************************/
-
- #if !defined( __DIR_H )
- #include <dir.h>
- #endif
-
- const ushort srNull = 0xFFFF;
- // srNull defines the End-Of-Structure identifier used by StrRef.
- // Because it identifies the last element in a StrRef structure, you
- // cannot use srNull's value as a string id, or Strings will stop
- // reading the structure when the element is encountered. If you
- // absolutely MUST use the 0xFFFF id for a string, change srNull to
- // a value 0..0xFFFF you are NOT using.
-
- /********************************************************************/
- /* Structure: StrRef */
- /* Description: */
- /* StrRef is the static structure that Strings uses to ref a */
- /* a string - it includes the string id, and an asciiz string which*/
- /* holds the string value. When creating a static array of StrRef */
- /* for use with Strings, the last entry in the array MUST have */
- /* srNull (defined above) as the id value. */
- /********************************************************************/
-
- struct StrRef
- {
- ushort id;
- char *str;
- };
-
- /********************************************************************/
- /* Class: Strings */
- /* Description: */
- /* Strings is a string-reference class that allows abstraction */
- /* of string usage in a TV application. Use Strings to access char */
- /* display data (max string lengh = 256 for string resource files) */
- /* so that the actual char strings are isolated to one location */
- /* (either an array of StrRef or a string resource file). There are*/
- /* two sources of data for Strings: either a StrRef array, or a */
- /* string resource file. For either source, multiple instances of */
- /* Strings can use the same source. For a StrRef array source, */
- /* Strings does not "own" the array; so if the array is dynamically*/
- /* allocated, it is up to the calling function to discard the array*/
- /* when it is no longer needed. */
- /********************************************************************/
-
- class far TStringList;
- class far ifpstream;
-
- class Strings
- {
- public:
-
- Strings(); // create an empty Strings.
- Strings( Strings& s ); // copy ctor.
- ~Strings(); // clean up.
-
- char *operator[] ( ushort id ); // return pointer to string
- char *get( ushort id ); // referenced by id.
-
- void clear(); // clear Strings, make it empty.
- Boolean load( StrRef *arg ); // load from a StrRef array.
- Boolean load( char *fspec ); // load from the string resource
- // whose name is fspec.
- Boolean store( char *fspec ); // create a string resource file with
- // the name fspec and write contents
- // to it. NOTE: can only be used if
- // load(StrRef *) was called to make
- // Strings.
-
- protected:
-
- StrRef **items; // array of pointers to StrRef items.
- // Sorted by id.
- int count; // Number of entries in items.
- Boolean search( ushort id, int& pos );
- // used by load(StrRef *) and get()
- // to find an id's position in items.
-
- ifpstream *is; // pointer to string resource file.
- TStringList *slist; // TStringList for srf.
- char buf[256]; // internal buffer for get()
- char fname[MAXPATH]; // srf file name (for copy ctor).
- };
-
- inline char *Strings::operator[] ( ushort id )
- { return get(id); }
-
- #endif // __Strings
-